from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-18 14:30:54.652499
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 18, Jan, 2021
Time: 14:30:58
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.2734
Nobs: 175.000 HQIC: -46.2408
Log likelihood: 1959.01 FPE: 4.28215e-21
AIC: -46.9010 Det(Omega_mle): 2.59692e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.452809 0.146731 3.086 0.002
L1.Burgenland 0.134978 0.076493 1.765 0.078
L1.Kärnten -0.235520 0.062121 -3.791 0.000
L1.Niederösterreich 0.134729 0.176776 0.762 0.446
L1.Oberösterreich 0.226398 0.151437 1.495 0.135
L1.Salzburg 0.179577 0.080418 2.233 0.026
L1.Steiermark 0.083372 0.109834 0.759 0.448
L1.Tirol 0.157404 0.072794 2.162 0.031
L1.Vorarlberg 0.015995 0.069464 0.230 0.818
L1.Wien -0.134788 0.147490 -0.914 0.361
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515017 0.187647 2.745 0.006
L1.Burgenland 0.013706 0.097823 0.140 0.889
L1.Kärnten 0.372094 0.079444 4.684 0.000
L1.Niederösterreich 0.122326 0.226071 0.541 0.588
L1.Oberösterreich -0.175738 0.193665 -0.907 0.364
L1.Salzburg 0.178248 0.102843 1.733 0.083
L1.Steiermark 0.244992 0.140461 1.744 0.081
L1.Tirol 0.143699 0.093092 1.544 0.123
L1.Vorarlberg 0.191850 0.088834 2.160 0.031
L1.Wien -0.592323 0.188618 -3.140 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301441 0.065313 4.615 0.000
L1.Burgenland 0.110380 0.034049 3.242 0.001
L1.Kärnten -0.024156 0.027652 -0.874 0.382
L1.Niederösterreich 0.050293 0.078688 0.639 0.523
L1.Oberösterreich 0.276371 0.067408 4.100 0.000
L1.Salzburg 0.003238 0.035796 0.090 0.928
L1.Steiermark -0.015293 0.048890 -0.313 0.754
L1.Tirol 0.094401 0.032402 2.913 0.004
L1.Vorarlberg 0.128068 0.030920 4.142 0.000
L1.Wien 0.081306 0.065652 1.238 0.216
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211278 0.076711 2.754 0.006
L1.Burgenland -0.006465 0.039991 -0.162 0.872
L1.Kärnten 0.024608 0.032477 0.758 0.449
L1.Niederösterreich 0.028476 0.092419 0.308 0.758
L1.Oberösterreich 0.383717 0.079172 4.847 0.000
L1.Salzburg 0.094302 0.042043 2.243 0.025
L1.Steiermark 0.186146 0.057422 3.242 0.001
L1.Tirol 0.044399 0.038057 1.167 0.243
L1.Vorarlberg 0.100665 0.036316 2.772 0.006
L1.Wien -0.069338 0.077108 -0.899 0.369
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.562493 0.152498 3.689 0.000
L1.Burgenland 0.075309 0.079500 0.947 0.343
L1.Kärnten 0.005005 0.064563 0.078 0.938
L1.Niederösterreich -0.021669 0.183724 -0.118 0.906
L1.Oberösterreich 0.134410 0.157389 0.854 0.393
L1.Salzburg 0.047358 0.083579 0.567 0.571
L1.Steiermark 0.112316 0.114151 0.984 0.325
L1.Tirol 0.224634 0.075655 2.969 0.003
L1.Vorarlberg 0.019768 0.072194 0.274 0.784
L1.Wien -0.145045 0.153287 -0.946 0.344
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161871 0.108237 1.496 0.135
L1.Burgenland -0.022287 0.056426 -0.395 0.693
L1.Kärnten -0.012349 0.045824 -0.269 0.788
L1.Niederösterreich 0.162641 0.130401 1.247 0.212
L1.Oberösterreich 0.380111 0.111709 3.403 0.001
L1.Salzburg -0.031174 0.059321 -0.526 0.599
L1.Steiermark -0.041772 0.081020 -0.516 0.606
L1.Tirol 0.192401 0.053697 3.583 0.000
L1.Vorarlberg 0.051198 0.051241 0.999 0.318
L1.Wien 0.166625 0.108798 1.532 0.126
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.226495 0.136754 1.656 0.098
L1.Burgenland 0.072539 0.071292 1.017 0.309
L1.Kärnten -0.050048 0.057897 -0.864 0.387
L1.Niederösterreich -0.057981 0.164756 -0.352 0.725
L1.Oberösterreich -0.097584 0.141140 -0.691 0.489
L1.Salzburg 0.029797 0.074950 0.398 0.691
L1.Steiermark 0.380781 0.102366 3.720 0.000
L1.Tirol 0.505983 0.067844 7.458 0.000
L1.Vorarlberg 0.197520 0.064741 3.051 0.002
L1.Wien -0.205563 0.137462 -1.495 0.135
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.100684 0.159501 0.631 0.528
L1.Burgenland 0.015591 0.083150 0.187 0.851
L1.Kärnten -0.104513 0.067528 -1.548 0.122
L1.Niederösterreich 0.233690 0.192161 1.216 0.224
L1.Oberösterreich 0.022530 0.164617 0.137 0.891
L1.Salzburg 0.222039 0.087417 2.540 0.011
L1.Steiermark 0.139010 0.119393 1.164 0.244
L1.Tirol 0.096216 0.079129 1.216 0.224
L1.Vorarlberg 0.019752 0.075509 0.262 0.794
L1.Wien 0.263059 0.160326 1.641 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590903 0.086770 6.810 0.000
L1.Burgenland -0.021540 0.045234 -0.476 0.634
L1.Kärnten -0.001463 0.036736 -0.040 0.968
L1.Niederösterreich -0.021452 0.104537 -0.205 0.837
L1.Oberösterreich 0.277872 0.089553 3.103 0.002
L1.Salzburg 0.009217 0.047556 0.194 0.846
L1.Steiermark 0.004384 0.064951 0.068 0.946
L1.Tirol 0.077450 0.043047 1.799 0.072
L1.Vorarlberg 0.169173 0.041078 4.118 0.000
L1.Wien -0.079453 0.087219 -0.911 0.362
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.150386 -0.004213 0.214423 0.254765 0.065875 0.084761 -0.069150 0.155133
Kärnten 0.150386 1.000000 0.007308 0.193549 0.158023 -0.123523 0.164963 0.028586 0.305991
Niederösterreich -0.004213 0.007308 1.000000 0.290947 0.086780 0.222966 0.111697 0.056931 0.353771
Oberösterreich 0.214423 0.193549 0.290947 1.000000 0.293144 0.312608 0.086582 0.079021 0.123346
Salzburg 0.254765 0.158023 0.086780 0.293144 1.000000 0.159413 0.072431 0.077711 -0.021791
Steiermark 0.065875 -0.123523 0.222966 0.312608 0.159413 1.000000 0.109088 0.088768 -0.113470
Tirol 0.084761 0.164963 0.111697 0.086582 0.072431 0.109088 1.000000 0.145259 0.136061
Vorarlberg -0.069150 0.028586 0.056931 0.079021 0.077711 0.088768 0.145259 1.000000 0.094786
Wien 0.155133 0.305991 0.353771 0.123346 -0.021791 -0.113470 0.136061 0.094786 1.000000